package main

import (
	"context"
	"time"
	server "v8s/http-server"

	"v8s/logger"

	"v8s-api/internal/configuration"
	"v8s-api/internal/db"
	"v8s-api/internal/rest-api"
	"v8s-api/rest-api/target/generated-sources"
)

func main() {
	properties := configuration.ReadProperties()

	logger.BuildLogger(properties.Log)

	ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
	client := db.CreateMongoClient(ctx, properties.Mongo)
	cancel()

	repository := db.CreateProjectsRepository(client, properties.Mongo)
	handlers := rest.NewHandlers(repository, properties.Features)
	httpServer := server.NewServer(properties.HttpServer, false)
	managementServer := server.NewServer(properties.ManagementHttpServer, true)

	generated.RegisterHandlers(httpServer, handlers)

	errors := server.RunServers(httpServer, managementServer)

	select {
	case err := <-errors:
		panic(err)
	}
}
